'''
利随本清的还款方式
'''
from date_utils import *


def one_time_repay(amount, day_rate, charge_rate, term, beg_interest):
    """
    :param amount: 借款本金
    :param day_rate:借款日利率
    :param charge_rate:借款月手续费
    :param term:借款期限（月）
    :param beg_interest:计息日
    :return: 用户的还款计划
    """
    repay_list = []  # 还款计划
    end_date = date_add(beg_interest, term, datetime.month)  # 计算到期日
    interest_days = date_diff(beg_interest, end_date)  # 计算计息天数
    interest = amount * day_rate * interest_days  # 计算总利息
    total_fee = amount * charge_rate * term

    # 封装还款计划
    repay_item = dict()
    repay_item["index"] = 1  # 期数
    repay_item["beg_interest"] = format_date(beg_interest, "%Y-%m-%d")  # 起息日期
    repay_item["interest_days"] = interest_days  # 计息天数
    repay_item["end_date"] = format_date(end_date, "%Y-%m-%d")  # 还款日期
    repay_item["amount"] = amount  # 应还本金
    repay_item["interest"] = interest  # 应还利息
    repay_item["total_fee"] = total_fee  # 应还费用
    repay_item["total_amount"] = amount + interest + total_fee  # 期供金额
    repay_item["remain_amount"] = 0  # 剩余本金

    repay_list.append(repay_item)

    return repay_list
